package com.berry.MedCheck;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageView;
import android.widget.PopupMenu;
import com.berry.MedCheck.db.DBMonitorService;
import com.berry.MedCheck.widget.SettingItemWidget;

/**
 * Created with IntelliJ IDEA.
 * User: Airay.Rong
 * Date: 13-12-4
 * Time: 下午2:38
 * To change this template use File | Settings | File Templates.
 */
public class SettingActivity extends BaseActivity implements View.OnClickListener {
	private SettingItemWidget mItemRecord;
	private SettingItemWidget mItemUser;
	private SettingItemWidget mItemAbout;
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.setting_activity);

		mItemRecord = (SettingItemWidget) findViewById(R.id.item_record);
		mItemRecord.setOnClickListener(this);

		mItemUser = (SettingItemWidget) findViewById(R.id.item_user);
		mItemUser.setOnClickListener(this);

		mItemAbout = (SettingItemWidget) findViewById(R.id.item_about);
		mItemAbout.setOnClickListener(this);
		setupMenuCallback();
	}
	private void setupMenuCallback() {
		mListener = new MenuCallback() {
			@Override
			public void onMenuClick(int id) {
				finish();
			}
		};
	}

	@Override
	public void onClick(View v) {
		if (mItemRecord == v) {
			startActivity(new Intent().setClass(this,ClearAllRecordActivity.class));
		}
		if (mItemUser == v) {
			//showPopMenu_UserList(v);
			startService(new Intent()
					.setClass(this, DBMonitorService.class));
			startActivity(new Intent().setClass(this, ChooseUserActivity.class)
					.putExtra("show_menu_btn", true));
			finish();
		}
		if (mItemAbout == v) {
			startActivity(new Intent().setClass(this,AboutActivity.class));
			finish();
		}
	}

//	private void showPopMenu_UserList(View view) {
//		ImageView mArrow = ((SettingItemWidget)view).getArrow();
//		PopupMenu popup = new PopupMenu(this, mArrow);
//		popup.getMenuInflater().inflate(R.menu.user_menu, popup.getMenu());
//
//		popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
//			public boolean onMenuItemClick(MenuItem item) {
//				if (item.getItemId() == R.id.add_new) {
//					startActivity(new Intent().setClass(SettingActivity.this,AddNewUserActivity.class));
//				}
//				return true;
//			}
//		});
//
//		popup.show();
//	}

//	private void showPopMenu_ClearUserRecord(View view) {
//		ImageView mArrow = ((SettingItemWidget)view).getArrow();
//		PopupMenu popup = new PopupMenu(this, mArrow);
//		popup.getMenuInflater().inflate(R.menu.clear_record_menu, popup.getMenu());
//
//		popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
//			public boolean onMenuItemClick(MenuItem item) {
////				Toast.makeText(PopupMenu1.this, "Clicked popup menu item " + item.getTitle(),
////						Toast.LENGTH_SHORT).show();
//				return true;
//			}
//		});
//
//		popup.show();
//
//	}
}